{extend name="public/base" /}

{block name="content"}
<style>
    .img-responsive [data-ratio="16:9"]{
        height: 7rem;
    }
    .test{
        border-radius: 0%;
        width: 100%;
        padding-bottom: 6%;
        line-height:9vw;
    }
</style>
<!--页面路径 和 页面标题-->
<div class="page-title">

    <div class="title-env">
        <h1 class="title">视频管理</h1>
        <p class="description">新增视频信息</p>
    </div>

    <div class="breadcrumb-env">

        <ol class="breadcrumb bc-1">
            <li>
                <a href="/admin"><i class="fa-home"></i>Home</a>
            </li>
            <li>
                <a href="/admin/video/index">视频管理</a>
            </li>
            <li class="active">
                <strong>视频信息</strong>
            </li>
        </ol>

    </div>

</div>

<div class="row">
    <div class="col-md-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">添加视频</font></font></h3>
            </div>

            <div class="panel-body">
                <form id="add-form" method="post" class="form-horizontal" action="/admin/video/addPost" id="add-form" enctype="multipart/form-data">

                    <div class="form-group" id="show-div" style="display: none">
                        <label class="col-sm-2 control-label">文件预览</label>
                        <div class="col-sm-3">
                            <img src="" id="show_poster_url" class="test" style="display:none;"/>
                        </div>
                        <div class="col-sm-3">
                            <video src="" id="show_video_url" controls="controls" class="test" style="display:none;"></video>
                        </div>
                        <div class="col-sm-3">
                            <video src="" id="show_demo_video_url" controls="controls" class="test" style="display:none;"></video>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">文件上传</label>
                        <div class="col-sm-3">
                            <div id="advancedDropzone" class="droppable-area test">
                                点击上传封面
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div id="advancedDropzone1" class="droppable-area test">
                                点击上传视频
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div id="advancedDropzone2" class="droppable-area test">
                                点击上传试看视频
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">视频标签</label>
                        <div class="col-sm-6">
                            <script type="text/javascript">
                                jQuery(document).ready(function($)
                                {
                                    $("#s2example-2").select2({
                                        placeholder: 'Choose your tag',
                                        allowClear: true
                                    }).on('select2-open', function()
                                    {
                                        // Adding Custom Scrollbar
                                        $(this).data('select2').results.addClass('overflow-hidden').perfectScrollbar();
                                    });

                                });
                            </script>

                            <select class="form-control" id="s2example-2" name="tag[]" multiple>
                                <option></option>
                                <optgroup label="标签列表">
                                    {foreach $tags as $tag}
                                    <option value="{$tag.name}">{$tag.name}</option>
                                    {/foreach}
                                </optgroup>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">所属分类</label>
                        <div class="col-sm-6">
                            <script type="text/javascript">
                                jQuery(document).ready(function($)
                                {
                                    $("#s2example-3").select2({
                                        placeholder: 'Choose your tag',
                                        allowClear: true
                                    }).on('select2-open', function()
                                    {
                                        // Adding Custom Scrollbar
                                        $(this).data('select2').results.addClass('overflow-hidden').perfectScrollbar();
                                    });

                                });
                            </script>

                            <select class="form-control" id="s2example-3" name="cate_id">
                                <option></option>
                                {foreach $cates as $cate}
                                <option value="{$cate.id}">{$cate.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">所属专家</label>
                        <div class="col-sm-4">
                            <script type="text/javascript">
                                jQuery(document).ready(function($)
                                {
                                    $("#s2example-1").select2({
                                        placeholder: '选择所属专家...',
                                        allowClear: true
                                    }).on('select2-open', function()
                                    {
                                        // Adding Custom Scrollbar
                                        $(this).data('select2').results.addClass('overflow-hidden').perfectScrollbar();
                                    });

                                });
                            </script>

                            <select class="form-control" id="s2example-1" name="channel_id">
                                <option></option>
                                <optgroup label="专家列表">
                                    {foreach $channels as $channel}
                                    <option value="{$channel.id}">{$channel.name}</option>
                                    {/foreach}
                                </optgroup>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">标题</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">描述</label>
                        <div class="col-sm-6">
                            <textarea class="form-control" rows="10" name="desc"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">价格</label>
                        <div class="col-sm-2">
                            <input type="number" class="form-control" name="price" value="0">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">分享访问次数</label>
                        <div class="col-sm-2">
                            <input type="text" class="form-control" name="shares_count" value="0">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">下载次数</label>
                        <div class="col-sm-2">
                            <input type="text" class="form-control" name="download_count" value="0">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">播放次数</label>
                        <div class="col-sm-2">
                            <input type="text" class="form-control" name="played_count" value="0">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">收藏数</label>
                        <div class="col-sm-2">
                            <input type="text" class="form-control" name="favorites_count" value="0">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">第三方名字</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" name="share_name">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">分享链接</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="share_url">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">推送时间</label>

                        <div class="col-sm-6">
                            <div class="date-and-time">
                                <input type="text" class="form-control datepicker" name="date" data-format="yyyy-mm-dd">
                                <input type="text" class="form-control timepicker" name="time" data-template="dropdown" data-show-seconds="true"/>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">允许下载</label>
                        <div class="col-sm-6">
                            <label class="radio-inline"><input type="radio" name="downloadable" value="1" checked>是</label>
                            <label class="radio-inline"><input type="radio" name="downloadable" value="2">否</label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">是否免费</label>
                        <div class="col-sm-6">
                            <label class="radio-inline"><input type="radio" name="is_free" value="1" checked>免费</label>
                            <label class="radio-inline"><input type="radio" name="is_free" value="2">否</label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">是否置顶</label>
                        <div class="col-sm-6">
                            <label class="radio-inline"><input type="radio" name="is_top" value="1" checked>否</label>
                            <label class="radio-inline"><input type="radio" name="is_top" value="2">是</label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">状态</label>
                        <div class="col-sm-6">
                            <label class="radio-inline"><input type="radio" name="status" value="1" checked>发布</label>
                            <label class="radio-inline"><input type="radio" name="status" value="2">隐藏</label>
                        </div>
                    </div>

                    <div class="form-group">
                        <input type="hidden" value="" name="poster_url" id="poster_url">
                        <input type="hidden" value="" name="video_url" id="video_url">
                        <input type="hidden" value="" name="demo_video_url" id="demo_video_url">
                        <input type="submit" class="btn btn-info btn-single pull-right" id="add-button" value="Save changes">

                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="modal"}

<div class="modal fade bs-example-modal-lg" id="upload-show" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">上传进度</h4>
            </div>
            <div class="modal-body">
                <div class="page-container">
                    <div class=" main-content ">
                        <div class="row table-responsive">
                            <table class="table table-bordered table-striped" id="example-dropzone-filetable">
                                <thead>
                                <tr>
                                    <th class="text-center">#</th>
                                    <th>Name</th>
                                    <th>Upload Progress</th>
                                    <th>Size</th>
                                    <th>Status</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr>
                                    <td colspan="5">Files list will appear here</td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>

                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-warning" id="cancel">取消上传</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

{/block}

{block name="js"}
<script src="/static/assets/js/dropzone/dropzone.js"></script>
<script src="/static/assets/js/webuploader/webuploader.min.js"></script>
<script src="/static/assets/js/datepicker/bootstrap-datepicker.js"></script>
<script src="/static/assets/js/timepicker/bootstrap-timepicker.min.js"></script>

<!--<script>

    //添加分类表单提交
    $("#add-button").click(function(){
        var targetUrl = $("#add-form").attr("action");
        var data = $("#add-form").serialize();
        $.ajax({
            type:'post',
            url:targetUrl,
            cache: false,
            data:data,
            dataType:'json',
            success:function(data){
                if(data.code == 0) {
                    success(data.message);
                    setTimeout("window.location.href='/admin/video/index'",1000);
                }else{
                    error(data.message);
                }
            }
        })
    });

</script>-->

<script type="text/javascript">
    jQuery(document).ready(function($)
    {
        var i = 1,
            $example_dropzone_filetable = $("#example-dropzone-filetable"),
            example_dropzone = $("#advancedDropzone").dropzone({
                url: '/admin/video/uploadFile',
                parallelUploads: 1,//一次上传的文件数量
                maxFiles:1,//一次性上传的文件数量上限
                maxFilesize:500, //上传文件最大尺寸
                init: function () {
                    var submitButton = document.querySelector("#cancel")
                    myDropzone = this;
                    submitButton.addEventListener("click", function () {
                        myDropzone.removeAllFiles(true);
                    });
                },
                // Events
                addedfile: function(file)
                {
                    $('#upload-show').modal('toggle')

                    $example_dropzone_filetable.find('tbody').html('');

                    var size = parseInt(file.size/1024, 10);
                    size = size < 1024 ? (size + " KB") : (parseInt(size/1024, 10) + " MB");

                    var	$el = $('<tr>\
                                        <td class="text-center">'+(i++)+'</td>\
                                        <td>'+file.name+'</td>\
                                        <td><div class="progress progress-striped"><div class="progress-bar progress-bar-warning"></div></div></td>\
                                        <td>'+size+'</td>\
                                        <td>Uploading...</td>\
                                    </tr>');

                    $example_dropzone_filetable.find('tbody').append($el);
                    file.fileEntryTd = $el;
                    file.progressBar = $el.find('.progress-bar');
                },

                uploadprogress: function(file, progress, bytesSent)
                {
                    file.progressBar.width(progress + '%');
                },

                success: function(file,res)
                {
                    file.fileEntryTd.find('td:last').html('<span class="text-success">Success</span>');
                    file.progressBar.removeClass('progress-bar-warning').addClass('progress-bar-success');
                    if(res.code == 0) {
                        $('#add-form #poster_url').val(res.data.url);
                        $('#add-form #show_poster_url').attr('src',res.data.url);
                        $('#show-div').css('display','block');
                        $('#show_poster_url').css('display','block');
                        success(res.message);
                        $('#upload-show').modal('toggle')
                    }else{
                        file.fileEntryTd.find('td:last').html('<span class="text-danger">Failed</span>');
                        error(res.message);
                    }

                },

                //取消上传
                canceled: function (file) {
                    file.fileEntryTd.find('td:last').html('<span class="text-danger">Cancel</span>');
                    file.progressBar.removeClass('progress-bar-warning').addClass('progress-bar-red');
                },

                error: function(file)
                {
                    file.fileEntryTd.find('td:last').html('<span class="text-danger">Failed</span>');
                    file.progressBar.removeClass('progress-bar-warning').addClass('progress-bar-red');
                }
            });


        example_dropzone1 = $("#advancedDropzone1").dropzone({
            url: '/admin/video/uploadVideo',
            parallelUploads: 1,//一次上传的文件数量
            maxFiles:1,//一次性上传的文件数量上限
            maxFilesize:500, //上传文件最大尺寸
            init: function () {
                var submitButton = document.querySelector("#cancel")
                myDropzone1 = this;
                submitButton.addEventListener("click", function () {
                    myDropzone1.removeAllFiles(true);
                });
            },
            // Events
            addedfile: function(file)
            {
                $('#upload-show').modal('toggle')

                $example_dropzone_filetable.find('tbody').html('');

                var size = parseInt(file.size/1024, 10);
                size = size < 1024 ? (size + " KB") : (parseInt(size/1024, 10) + " MB");

                var	$el = $('<tr>\
                                <td class="text-center">'+(i++)+'</td>\
                                <td>'+file.name+'</td>\
                                <td><div class="progress progress-striped"><div class="progress-bar progress-bar-warning"></div></div></td>\
                                <td>'+size+'</td>\
                                <td>Uploading...</td>\
                            </tr>');

                $example_dropzone_filetable.find('tbody').append($el);
                file.fileEntryTd = $el;
                file.progressBar = $el.find('.progress-bar');
            },

            uploadprogress: function(file, progress, bytesSent)
            {
                file.progressBar.width(progress + '%');
            },

            success: function(file,res)
            {
                file.fileEntryTd.find('td:last').html('<span class="text-success">Success</span>');
                file.progressBar.removeClass('progress-bar-warning').addClass('progress-bar-success');
                if(res.code == 0) {
                    $('#add-form #video_url').val(res.data.url);
                    $('#add-form #show_video_url').attr('src',res.data.url);
                    $('#show-div').css('display','block');
                    $('#show_video_url').css('display','block');
                    success(res.message);
                    $('#upload-show').modal('toggle')
                }else{
                    file.fileEntryTd.find('td:last').html('<span class="text-danger">Failed</span>');
                    error(res.message);
                }

            },

            //取消上传
            canceled: function (file) {
                file.fileEntryTd.find('td:last').html('<span class="text-danger">Cancel</span>');
                file.progressBar.removeClass('progress-bar-warning').addClass('progress-bar-red');
            },

            error: function(file)
            {
                file.fileEntryTd.find('td:last').html('<span class="text-danger">Failed</span>');
                file.progressBar.removeClass('progress-bar-warning').addClass('progress-bar-red');
            }
        });

        example_dropzone2 = $("#advancedDropzone2").dropzone({
            url: '/admin/video/uploadVideo',
            parallelUploads: 1,//一次上传的文件数量
            maxFiles:1,//一次性上传的文件数量上限
            maxFilesize:500, //上传文件最大尺寸
            init: function () {
                var submitButton = document.querySelector("#cancel")
                myDropzone2 = this;
                submitButton.addEventListener("click", function () {
                    myDropzone2.removeAllFiles(true);
                });
            },
            // Events
            addedfile: function(file)
            {
                $('#upload-show').modal('toggle')
                $example_dropzone_filetable.find('tbody').html('');

                var size = parseInt(file.size/1024, 10);
                size = size < 1024 ? (size + " KB") : (parseInt(size/1024, 10) + " MB");
                var	$el = $('<tr>\
                                <td class="text-center">'+(i++)+'</td>\
                                <td>'+file.name+'</td>\
                                <td><div class="progress progress-striped"><div class="progress-bar progress-bar-warning"></div></div></td>\
                                <td>'+size+'</td>\
                                <td>Uploading...</td>\
                            </tr>');

                $example_dropzone_filetable.find('tbody').append($el);
                file.fileEntryTd = $el;
                file.progressBar = $el.find('.progress-bar');
            },

            uploadprogress: function(file, progress, bytesSent)
            {
                file.progressBar.width(progress + '%');
            },

            success: function(file,res)
            {
                file.fileEntryTd.find('td:last').html('<span class="text-success">Success</span>');
                file.progressBar.removeClass('progress-bar-warning').addClass('progress-bar-success');
                if(res.code == 0) {
                    $('#add-form #demo_video_url').val(res.data.url);
                    $('#add-form #show_demo_video_url').attr('src',res.data.url);
                    $('#show-div').css('display','block');
                    $('#show_demo_video_url').css('display','block');
                    success(res.message);
                    $('#upload-show').modal('toggle')
                }else{
                    file.fileEntryTd.find('td:last').html('<span class="text-danger">Failed</span>');
                    error(res.message);
                }

            },

            //取消上传
            canceled: function (file) {
                file.fileEntryTd.find('td:last').html('<span class="text-danger">Cancel</span>');
                file.progressBar.removeClass('progress-bar-warning').addClass('progress-bar-red');
            },

            error: function(file)
            {
                file.fileEntryTd.find('td:last').html('<span class="text-danger">Failed</span>');
                file.progressBar.removeClass('progress-bar-warning').addClass('progress-bar-red');
            }
        });
    });
</script>
{/block}